package kr.hkit.powerjava.chapter22.collection;

public class Array {
	public static <T> T getlast(T[] a) {
		return a[a.length - 1];
	}

	public static void main(String[] args) {
		String[] language = { "JAVA", "C#", "C++", "BASIC" };
		Integer[] arr = { 5, 4, 3, 2, 1 };

		String last = Array.getlast(language);
		System.out.println(last);
		int aLast = Array.getlast(arr);
		System.out.println(aLast);

		System.out.println(Array.getMax(arr));
	}

	public static <T extends Comparable> T getMax(T[] a) {
		if (a == null || a.length == 0)
			return null;
		T largest = a[0];
		for (int i = 1; i < a.length; i++)
			if (largest.compareTo(a[i]) < 0)
				largest = a[i];
		return largest;
	}
}
